import {getMenuConfig} from "../../api/sidebarMenuConfig";

import {createMenu} from "src/utils/synb-utils";

export default {
  namespaced: true,
  state: {
    leftMenu: []
  },
  mutations: {
    SET_LEFT_MENU(state, data) {
      // let initArray = [
      //   {
      //     path: '/',
      //     redirect: '/index',
      //     children: [{
      //       path: 'index',
      //       name: 'Home',
      //       meta: {title: '首页', icon: 'dashboard',}
      //     }]
      //   }
      // ];
      state.leftMenu = data;
    }
  },
  actions: {
    setLeftMenu({commit}, data) {
      return new Promise((resolve, reject) => {
        getMenuConfig({}).then(res => {
          let {category_list, api_domain} = res.data;
          let createMenuOk = createMenu(category_list);
          commit('SET_LEFT_MENU', createMenuOk)
          resolve()
        }).catch(error => {
          console.log(error);
          reject(error)
        })
      })
    }
  }
}
